(function ($) {
	var onlinePull;
	var onlinePage = 1,Limit = 20;
	var onlinePulling = false;
	var onlineData;
	$.init();
	$.plusReady(function () {
	    baseSetup();
	})
	if (!mui.os.plus) {
		baseSetup()
	}
	
	//必修课--预约
	function getOnlineData(){
		if (onlinePulling) {
			onlinePull.endPullUpToRefresh()
			return;
		}
		onlinePulling = true
		setTimeout(function(){
			var dataArr = [{},{},{}]
			onlinePull.endPullUpToRefresh();
			if (onlinePage > 2) {
				onlinePull.endPullUpToRefresh(true);
			}
			updateUI(dataArr)
			onlinePage += 1;
			onlinePulling = false
		},800);
	}
	function updateUI(dataArr){
		var onlineUL = document.getElementById("onlineUL");
		if (onlinePage == 1) {
			onlineUL.innerHTML = ''
		}
		
		for(var i=0; i<dataArr.length; i++){
			var html = '<div class="classTitle">2021年第一次三基理论考核</div>'+
				'<div class="classInfo">院级 | 护士层级:N0,N1,N2</div>'+
				'<div class="classSubInfo">考核时间：2021.06.18 - 2021.06.28</div>';
			if (i == 2) {
				html = '<div class="classTitle">2021年第一次三基理论培训</div>'+
					'<div class="classInfo">院级 |  日常培训 | 线上培训 | 必修 | 3分</div>'+
					'<div class="classSubInfo">培训日期：2021.06.18 - 2021.06.28</div>';
			}
			var newLi = document.createElement('li')
			newLi.setAttribute('class','mui-table-view-cell')
			newLi.innerHTML = html
			
			onlineUL.appendChild(newLi)
			newLi.addEventListener('tap',tableViewCellTapped)
		}
	}
	
	function tableViewCellTapped(){
		var title = this.querySelector('.classTitle').innerHTML
		var webview = plus.webview.create('onlinePerson.html', 'onlinePerson', {
			background: '#fff',
			statusbar: {
				background: '#fff'
			}
		},{sourceData:{'title':title},pageType:''});
		webview.show('fade-in');
	}
	
	function baseSetup(){
		$('.mui-scroll-wrapper').scroll({
			bounce: true,
			indicators: false, //是否显示滚动条
		});
		mui("body").on("tap", ".searchArea .mui-icon-clear", function() {
			if (document.getElementById('search').value != "") {
				document.getElementById('search').value = ""
			}
			resetRefresh()
		});
		var search = document.getElementById('search');
		search.addEventListener('input',function(){
			resetRefresh()
		});
		//预约
		var onlineScroll = document.getElementById('onlineScroll');
		onlinePull = $(onlineScroll).pullToRefresh({
			up: {
				callback: function() {
					getOnlineData()
				}
			}
		});
		getOnlineData();
	}

	function resetRefresh(){
		onlinePage = 1;
		onlineData = []
		if (onlinePull) {
			onlinePull.refresh(true)
		}
		getOnlineData();
		$('#onlineWrapper').scroll().scrollTo(0,0,100);
	}
})(mui);